<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/map'

export default {
  name: 'App',
  mounted () {
    // console.log('写入用户信息')
    // window.localStorage.setItem('userInfo', '{"id":1,"department_id":4,"position_id":null,"openid":null,"small_openid":null,"account_openid":null,"unionid":"0","nickname":null,"avatar":null,"username":"admin","password":"6654e7f2b903854ec3d473f746d40a50","email":null,"truename":"管理员","mobile":null,"role_id":100,"status":null,"salt":"oDcQvRNU12Kp9OjmDNhJaPtk9psYigW3XbL6ZcrP","api_token":null,"is_boss":0,"is_yewu":null,"created_at":null,"updated_at":"2019-12-08 01:27:25","deleted_at":null,"source":null}')
    window.localStorage.setItem('userInfo', '{"id":66,"department_id":6,"position_id":5,"openid":"o2I6H5MFXzBr0J-aDfZpS_E5fuks","small_openid":"o2I6H5MFXzBr0J-aDfZpS_E5fuks","account_openid":null,"unionid":"oLT5G1mMtHvi5WFrrKnFwPWlN8ZQ","nickname":"Sven","avatar":"http://thirdwx.qlogo.cn/mmopen/vi_32/pZfGxK6YJEbdZaW6XPg66zPy15gbd2t3KmjBPNTS5WUPrtJKFPEd4FLkamAQAKKqiavEhbB9L6qFxLz6VRdldkA/132","username":null,"password":null,"email":null,"truename":null,"mobile":null,"role_id":1,"status":1,"salt":null,"api_token":"oIbF7wGUPggzOKACp9Dh7CzFNoSI","is_boss":0,"is_yewu":0,"created_at":"2019-06-16 17:57:09","updated_at":"2020-07-04 20:02:08","deleted_at":null,"source":"pc"}')
    // window.localStorage.setItem('token', 'oIbF7wGUPggzOKACp9Dh7CzFNoSI')
    const code = window.location.search.split('=')[1]
    if (code) {
      window.localStorage.setItem('token', code || window.localStorage.getItem('token'))
      this.token = window.localStorage.getItem('token')
      this.getLogin()
    }
    // else {
    //   window.location.href = window.location.origin + window.location.pathname
    // }
  },
  methods: {
    async getLogin () {
      const code = window.location.search.split('=')[1]
      const r = Math.random()
      const { data } = await getUserInfo(r)
      window.localStorage.setItem('userInfo', JSON.stringify(data))
      window.localStorage.setItem('token', code)
      // this.$router.push({ name: 'pointMap' })
      window.location.href = window.location.origin + window.location.pathname
    }
  }
}
</script>

<style lang="scss">
</style>
